package at.guigu.web;

import at.guigu.util.CheckCodeUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.OutputStream;

@WebServlet("/checkCodeServlet")
public class CheckCodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1 生成验证码
        //获取字节输出流
        ServletOutputStream sos = response.getOutputStream();
        //调用工具类获取验证码字符串数据并生成验证码数据图片
        String checkCode = CheckCodeUtil.outputVerifyImage(100, 50, sos, 4);
        //2 将系统自动生成的验证码字符串存入Session
        HttpSession session = request.getSession();
        session.setAttribute("checkCodeGen", checkCode);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}